<?php

namespace App\Http\Controllers;

use App\Models\System;
use Illuminate\Http\Request;

class SystemController extends Controller
{
  public function index()
  {
    $all = System::where('text', '!=', '')->get();
    return success($all);
  }

  public function update(Request $request, System $system)
  {
    $system->value = $request->value;
    $system->save();
    return success($system);
  }

  public function apiSwitchToggle(Request $request)
  {
    $request->validate([
      'val' => 'required|in:0,1'
    ]);

    System::where('key', 'api_switch')
      ->update([
        'value' => $request->val
      ]);
    return success('ok');
  }

  public function apiSwitch()
  {
    return success(sys('api_switch'));
  }
}
